import { CalculatorOutlined, FileDoneOutlined, GroupOutlined } from "@ant-design/icons";
import { SampleRecordEditType, SampleStep, SampleTable } from "../typing";
import getApiData from "@/services/cpasRequest";
import { msgError } from "@/utils/msg";
import { updateSampleTableArrayValue } from "./samplingSourceService";

export const steps = [
    {
        title: '1.确定项目总体',
        key: 0,
        icon: <FileDoneOutlined />,
    },
    {
        title: '2.确定抽样参数',
        key: 1,
        icon: <CalculatorOutlined />,
    },
    {
        title: '3.抽样样本',
        key: 2,
        icon: <GroupOutlined />,
    },
];
/**
 * 更新显示值
 * @param sampleStep 
 * @param stepCurrent 
 */
export const updateSampleStepDisplay = (sampleStep: SampleStep, stepCurrent: number) => {
    if (stepCurrent === 0) {
        sampleStep.step0Display = '';
        sampleStep.step1Display = 'none';
        sampleStep.step2Display = 'none';

    } else if (stepCurrent === 1) {
        sampleStep.step0Display = 'none';
        sampleStep.step1Display = '';
        sampleStep.step2Display = 'none';

    } else if (stepCurrent === 2) {
        sampleStep.step0Display = 'none';
        sampleStep.step1Display = 'none';
        sampleStep.step2Display = '';

    }
}

/**
 * 获取样本表
 * @returns 
 */
export const getSampleTableList = async (dbname: string, dataId: string,
    setSampleTableList?: (value: SampleTable[]) => void): Promise<SampleTable[]> => {

    const retData = await getApiData('sample.getSampleTableList', { dbname, dataId });
    if (!retData.ok) {
        msgError(retData.data);
        return []
    }

    updateSampleTableArrayValue(retData.data);
    
    setSampleTableList && setSampleTableList(retData.data);
    return retData.data;
};
/**
 * 是否编辑后查看
 * @param sampleRecordEditType 
 * @returns 
 */
export function getIsEditOrView(sampleRecordEditType?: SampleRecordEditType) {
    return sampleRecordEditType && ([SampleRecordEditType.edit, SampleRecordEditType.view].includes(sampleRecordEditType))
}
export function getIsAdd(sampleRecordEditType?: SampleRecordEditType) {
    return sampleRecordEditType && ([SampleRecordEditType.add].includes(sampleRecordEditType))
}